package IO;

import java.io.File;
import java.io.IOException;
import java.util.Date;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/31 :20:09
 * @Description
 */
public class FileTest {
    public static void main(String[] args) throws IOException {
        File file1 = new File("E:\\javadev\\suanfa\\src\\IO\\Hello.txt");
        File file2 = new File("Hello.txt");
        File file3 = new File("E:\\javadev\\suanfa\\src", "IO");
        File file4 = new File(file3,"Hello.txt");
        System.out.println(file1);
        System.out.println(file2);
        System.out.println(file4);
        System.out.println("------------------------");
        System.out.println("文件绝对路径："+file2.getAbsoluteFile());
        System.out.println("文件路径："+file2.getPath());
        System.out.println("文件名："+file1.getName());
        System.out.println("文件父路径："+file1.getParentFile());
        System.out.println("文件最后修改时间："+new Date(file1.lastModified()));
        System.out.println("文件长度："+file2.length());
        File file5 = new File("E:\\javadev\\suanfa\\src");
        //路径下所有文件
        for (String s : file5.list()) {
            System.out.println(s);
        }
        File file6 = new File("E:\\javadev\\suanfa\\src\\IO\\hah");
        file6.mkdir();

        File file7 = new File("Hello.txt");
        if (file7.exists()){
            file7.delete();//不走回收站
            System.out.println("文件删除成功");
        }else {
            file7.createNewFile();
            System.out.println("文件创建成功");
        }
    }
}
